<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//最长公共前缀
			//输入：strs = ["flower","flow","flight"]
			//输出："fl"
			/**
			 * @param {string[]} strs
			 * @return {string}
			 */
			var longestCommonPrefix = function(strs) {
				if (strs.length == 0) return "";
				let ans = strs[0];
				for(let i =1;i<strs.length;i++) {
					// debugger
					let j=0;
					for(;j<ans.length && j < strs[i].length;j++) {
						if(ans[j] != strs[i][j])
							break;
					}
					ans = ans.substr(0, j);
					if(ans === "")
						return ans;
				}
				return ans;
			};
			console.log(longestCommonPrefix(["flower", "flow", "flight"]));
			// console.log(longestCommonPrefix(["dog","racecar","car"]));
		</script>
	</body>
</html>
